package www.openteam.com.presenter.business;

import android.graphics.Bitmap;

import java.io.File;
import java.util.HashMap;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.DlryNtPrimaryTable;
import www.openteam.com.bean.DlryNtSublist;
import www.openteam.com.bean.InsertStatus;
import www.openteam.com.bean.ShowSignature;
import www.openteam.com.contract.business.DlryNoteContract;
import www.openteam.com.model.business.DlryNoteModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.ui.business.DeliverNoteFragment;

/**
 * Created by Administrator on 2019-07-30.
 */

public class DeliveryNotePresenter extends BasePresenter<DeliverNoteFragment>
        implements DlryNoteContract.DlryNotePrst {

    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new DlryNoteModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> hashMap = new HashMap<>();
        hashMap.put("DeliveryNotePresenter", models[0]);
        return hashMap;
    }

    @Override
    public void getPrimaryData(String code) {
        ((DlryNoteModel) getiModelMap().get("DeliveryNotePresenter")).getPrimaryTable(code, new DlryNoteModel.PrimaryTableListener() {
            @Override
            public void success(DlryNtPrimaryTable dlryNtPrimaryTable) {
                getIView().getPrimaryData(dlryNtPrimaryTable);
            }

            @Override
            public void fail(String msg) {
                getIView().getPrimaryDataFail(msg);
            }
        });
    }

    @Override
    public void getSublistData(String code) {
        ((DlryNoteModel) getiModelMap().get("DeliveryNotePresenter")).getSublist(code, new DlryNoteModel.SublistListener() {
            @Override
            public void success(DlryNtSublist dlryNtSublist) {
                getIView().getSublistData(dlryNtSublist);
            }

            @Override
            public void fail(String msg) {
                getIView().getSublistFail(msg);
            }
        });
    }

    @Override
    public void postPicture(File file, String zbid, String returnMan, String returnDate, String returnStatus) {
        ((DlryNoteModel) getiModelMap().get("DeliveryNotePresenter")).postSignature(file, zbid, returnMan, returnDate, returnStatus,
                new DlryNoteModel.SignatureListener() {
                    @Override
                    public void success(InsertStatus insertStatus) {
                        getIView().postPicSuccess(insertStatus);
                    }

                    @Override
                    public void fail(String msg) {
                        getIView().postPicFail(msg);
                    }
                });
    }

    @Override
    public void cancleRecipe(String zbid) {
        ((DlryNoteModel) getiModelMap().get("DeliveryNotePresenter")).cancleRecipe(zbid, new DlryNoteModel.CancleRcpListener() {
            @Override
            public void success(InsertStatus insertStatus) {
                getIView().cancleRcpSuccess(insertStatus);
            }

            @Override
            public void fail(String msg) {
                getIView().cancleRcpFail(msg);
            }
        });
    }

    @Override
    public void showSignature(String zbid) {
        ((DlryNoteModel) getiModelMap().get("DeliveryNotePresenter")).showSignature(zbid, new DlryNoteModel.ShowSignatureListener() {
            @Override
            public void success(ShowSignature showSignature) {
                getIView().showSignature(showSignature);
            }

            @Override
            public void fail(String msg) {
                getIView().showgetSignatureFail(msg);
            }
        });
    }


}
